﻿using L.Tool;
using L.UI.Base;
using System.Collections.Generic;
using UnityEngine;

public class UIManager : MSingleton<UIManager>
{
    /// <summary>
    /// 缓存所有UI窗体
    /// </summary>
    public Dictionary<UIPanelType, BasePanel> allUIs = new Dictionary<UIPanelType, BasePanel>();

    // <summary>
    /// 添加缓存UI
    /// </summary>
    /// <param name="basePanel"></param>
    /// <param name="uIPanelType"></param>
    public void AddCacheUIs(BasePanel basePanel, UIPanelType uIPanelType)
    {
        allUIs.Add(uIPanelType, basePanel);
    }

    /// <summary>
    /// 关闭所示UI面本
    /// </summary>
    public void CloseAllUI()
    {
        //把正在显示集合 栈集合都隐藏
        foreach (var item in allUIs)
        {
            item.Value.OnActiveFalse();
        }
    }

    /// <summary>
    /// 打开/显示UI窗体
    /// </summary>
    public void ShowUI(UIPanelType uIPanelType)
    {
        allUIs.TryGetValue(uIPanelType, out BasePanel baseUIFromAll);
        baseUIFromAll.OnActiveTrue();
        baseUIFromAll.InitUI();
    }

    /// <summary>
    /// 关闭UI窗体
    /// </summary>
    public void CloseUI(UIPanelType uIPanelType)
    {
        allUIs.TryGetValue(uIPanelType, out BasePanel baseUIFromAll);
        baseUIFromAll.OnActiveFalse();
    }
}
